package com.ean.backpack.repository;

import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import com.ean.backpack.domain.Activepropertylist;

@Repository
public interface ActivepropertylistRepository extends
		JpaRepository<Activepropertylist, Integer>,
		JpaSpecificationExecutor<Activepropertylist> {

	List<Activepropertylist> findDistinctByCityContaining(String city, Pageable pageable);
	
	List<Activepropertylist> findDistinctByCityContainingAndCountryContaining(String term, String country, Pageable pageable);
	
	List<Activepropertylist> findDistinctByCityContainingAndCountryContainingAndStateProvinceContaining(String term, String country, String state, Pageable pageable);
	
	@Query(value="SELECT DISTINCT REPLACE(CONCAT_WS(', ', city, stateProvince, country), ', , ', ', ') FROM Activepropertylist AS a WHERE a.city Like '%' :cityparam '%' AND (a.stateProvince Like '%' :stateparam '%' AND a.country Like '%' :countryparam '%') LIMIT 10", nativeQuery = true)
	List<String> findByCity(@Param("cityparam") String city, @Param("countryparam") String country, @Param("stateparam") String state);
	
}

